package effectiveJava.staticMethod;
/**
 * 这个类设计成可以选的参数,取代构造器
 * @author ieei
 *
 */
public class Demo2 {
	private final String s1;
	private final String s2;
	private final String s3;
	private final String s4;
	public static class Build{
		//这个是2个必须的元素
		private final String s1;
		private final String s2;
		
		
		//这2个是可选的，带默认值
		private String s3="s3";
		private String s4="s4";
		public Build(String s1,String s2){
			this.s1=s1;
			this.s2=s2;
		}
		public Build s3(String s){
			s3=s;
			return this;
		}
		public Build s4(String s){
			s4=s;
			return this;
		}
		public Demo2 build(){
			return new Demo2(this);
		}
	}
	private Demo2(Build build){
		s1=build.s1;
		s2=build.s2;
		s3=build.s3;
		s4=build.s4;
	}
	public static void main(String[] args) {
		Demo2 demo2=new Demo2.Build("s1", "s2").s3("s6").build();
		System.out.println(demo2.s1+demo2.s2+demo2.s3+demo2.s4);
	}
}
